var t = require('../@babel/runtime/helpers/regeneratorRuntime.js'),
  e = require('../@babel/runtime/helpers/asyncToGenerator.js'),
  s = getApp(),
  a = require('BD790DC370B67DCFDB1F65C4F3901B27.js');
module.exports = Behavior({
  properties: {},
  options: {},
  data: { NavHeight: s.globalData.navBarHeight + s.globalData.statusBarHeight },
  pageLifetimes: {},
  created: function () {},
  attached: function () {},
  ready: function () {},
  methods: {
    hackB: function () {
      console.log('components/addressList/addressList hackB in');
    },
    _ipt: function (t) {
      var e = this;
      this.setData({ keyw: t.detail.value }, function () {
        e.doSearch();
      });
    },
    iptClear: function () {
      var t = this;
      this.setData({ keyw: '' }, function () {
        t.doSearch();
      });
    },
    doSearch: function () {
      var t = this.data,
        e = t.keyw,
        s = t.originData.filter(function (t) {
          return (
            -1 !==
            ''
              .concat(t.full_address)
              .concat(t.phone)
              .concat(t.name)
              .indexOf(e.trim())
          );
        });
      console.log(s), this.setData({ showData: s });
    },
    getAddressList: function () {
      var r = this;
      return e(
        t().mark(function e() {
          var n, i;
          return t().wrap(function (t) {
            for (;;)
              switch ((t.prev = t.next)) {
                case 0:
                  return (
                    (t.next = 2),
                    s.$api.user.getAddressList(
                      {},
                      {
                        notLoginFunction: function (t) {
                          console.log('notLoginFunction: ', t),
                            r.triggerEvent('notLogin');
                        },
                      },
                    )
                  );
                case 2:
                  (n = t.sent),
                    (i = n.items),
                    console.log(
                      'components/addressList/addressList, getAddressList in items: ',
                      i,
                    ),
                    i &&
                      i.length &&
                      r.setData({ originData: i, showData: i }, function () {
                        var t = a();
                        t && r.resetList_submitOrder(t);
                      });
                case 6:
                case 'end':
                  return t.stop();
              }
          }, e);
        }),
      )();
    },
    resetList_submitOrder: function (t) {
      for (
        var e,
          s = this.data,
          a = s.isGiftAddress,
          r = s.showData,
          n = [],
          i = 0 === a ? t.data.address_ids : t.data.gift_address_ids,
          o = 0;
        o < r.length;
        o++
      ) {
        var d = r[o];
        i == d.id ? ((d.isChoosed = !0), (e = d)) : n.push(d);
      }
      e && n.unshift(e), this.setData({ showData: n });
    },
    del: function (a) {
      var r = this;
      return e(
        t().mark(function e() {
          var n, i;
          return t().wrap(function (t) {
            for (;;)
              switch ((t.prev = t.next)) {
                case 0:
                  (n = a.currentTarget.dataset.addressid),
                    (i = r),
                    wx.showModal({
                      title: '确认删除这条地址？',
                      success: function (t) {
                        t.confirm &&
                          (i.setData({ originData: [], showData: [] }),
                          s.$api.user
                            .delAddress(
                              { id: n },
                              { success: !0, successDesc: '删除成功' },
                            )
                            .then(function (t) {
                              i.getAddressList();
                            }));
                      },
                    });
                case 3:
                case 'end':
                  return t.stop();
              }
          }, e);
        }),
      )();
    },
    copy: function (t) {
      var e = t.currentTarget.dataset.item;
      wx.setClipboardData({
        data: ''
          .concat(e.name, ' ')
          .concat(e.phone, ' ')
          .concat(e.full_address),
        success: function (t) {
          wx.showToast({ title: '已复制到粘贴板', duration: 1200 });
        },
      });
    },
    edit: function (t) {
      var e = t.currentTarget.dataset.addressid;
      wx.navigateTo({ url: '/pages/addressEdit/addressEdit?id='.concat(e) });
    },
    defaultTrigger: function (t) {
      var e = this,
        a = t.currentTarget.dataset.index,
        r = this.data.showData[a];
      s.$api.user.selectAddress({ id: r.id }).then(function (t) {
        wx.showToast({ title: '设置成功' }), e.getAddressList();
      });
    },
    create: function () {
      wx.navigateTo({ url: '/pages/addressEdit/addressEdit' });
    },
  },
});
